<template>
  <div>
    <a-table :columns="columns" :data="data">
      <template #agree="{ record }">
        <a-button @click="agreeSubmit(record.supSubname,record.supClassname,record.supId)">同意</a-button>
      </template>
      <template #reject="{ record }">
        <a-button @click="rejectSubmit(record.supSubname,record.supClassname,record.supId)">驳回</a-button>
      </template>
    </a-table>
  </div>
</template>
  
<script>
import { reactive } from "vue";
import axios from "axios";

export default {
  data() {
    const columns = [
      {
        title: "ID",
        dataIndex: "supId",
      },
      {
        title: "申请班级名称",
        dataIndex: "supClassname",
      },
      {
        title: "申请人",
        dataIndex: "supSubname",
      },
      {
        title: "处理情况",
        dataIndex: "supHandel",
      },
      {
        title: "同意",
        slotName: "agree",
      },
      {
        title: "驳回",
        slotName: "reject",
      },
    ];
    return {
      handle: "YES",
      columns,
      data: [
        {
          supId: 1,
          supClassname: "网安1班",
          supSubname: "cac",
          supHandel: "未处理",
        },
      ],
    };
  },
  methods: {
    agreeSubmit(master,className,id) {
      (this.handle = "YES"), this.handleAply(master,className,id);
      setTimeout(() => {
        this.searchInfo();
      }, 1000);
    },
    rejectSubmit(master,className,id) {
      (this.handle = "NO"), this.handleAply(master,className,id);
      setTimeout(() => {
        this.searchInfo();
      }, 1000);
    },
    handleAply(master,className,id) {
      axios
        .post("/handleClassAply", {
          classMaster: master,
          className: className,
          supId: id,
          isHandle: this.handle,
        })
        .then((response) => {
          if (response.data) {
            alert("操作成功");
          } else {
            alert("操作失败");
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    searchInfo() {
      axios
        .get("/getClassAplyInfo")
        .then((response) => {
          this.data = response.data;
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },

  created() {
    axios
      .get("/getClassAplyInfo")
      .then((response) => {
        this.data = response.data;
      })
      .catch(function (error) {
        console.log(error);
      });
  },
};
</script>
  